package net.wofly.sale.report.validator;


import net.wofly.common.util.DateUtil;
import net.wofly.common.util.ReturnBean;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils;

import java.text.ParseException;
import java.util.Date;

/**
 * Created by siqingwei on 2018/4/11.
 */
public class ReportValidator {
    /**
     * 换行符
     */
    private static String lineSeparator = System.getProperty("line.separator");

    public static String validateGetSaleDailyReportParams(String dateDay) {
        StringBuffer stringBuffer = new StringBuffer();
        if (StringUtils.isEmpty(dateDay)) {
            stringBuffer.append("日期不能为空！").append(lineSeparator);
        }

        try {
            DateUtils.parseDate(dateDay);
        } catch (ParseException e) {
            stringBuffer.append("日期格式不正确！").append(lineSeparator);
        }

        return stringBuffer.toString();
    }

    public static String validateGetSaleDailyReportDetailParams(String userID, Long countDate) {
        StringBuffer stringBuffer = new StringBuffer();
        if (StringUtils.isEmpty(userID)) {
            stringBuffer.append("用户ID不能为空！").append(lineSeparator);
        }

        if (countDate == null || countDate < 0) {
            stringBuffer.append("日期不能为空，或者日期不正确").append(lineSeparator);
        }

        Date date = new Date(countDate);
        if (date.after(DateUtil.processStartTime(new Date()))) {
            stringBuffer.append("不能选择当前日期之后的日期").append(lineSeparator);
        }

        return stringBuffer.toString();
    }

    public static String validateManagerOutStockSummaryParams(Long countDate) {
        return validateCountDate(countDate);
    }

    public static String validateStoreOutStockSummaryParams(Long countDate) {
        return validateCountDate(countDate);
    }

    private static String validateCountDate(Long countDate) {
        StringBuffer stringBuffer = new StringBuffer();
        if (countDate == null || countDate < 0) {
            stringBuffer.append("日期不能为空，或者日期不正确").append(lineSeparator);
        }
        return stringBuffer.toString();
    }

    public static String validateManagerInStockSummaryParams(Long countDate) {
        return validateCountDate(countDate);
    }

    public static String validateStoreInStockSummaryParams(Long countDate) {
        return validateCountDate(countDate);
    }

    public static String validateCommodityTerminalOutStockSummaryParams(Long countDate) {
        return validateCountDate(countDate);
    }
}
